import 'package:base/main.dart';
import 'package:flutter/material.dart';

class HomeFinanceWidget extends StatelessWidget {
  const HomeFinanceWidget({super.key});

  @override
  Widget build(BuildContext context) {
    final int padding = 10;
    final double margins = 16;

    final width = ScreenUtil.instance.designWidth / 2 - 32;
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16),
      alignment: Alignment.topLeft,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Text('财务中心',
              style: TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                  color: Colors.black)),
          SizedBox(height: 16),
          _buildFinanceDashboardWidget(),
        ],
      ),
    );
  }

  _buildFinanceDashboardWidget() {
    final width = ScreenUtil.instance.designWidth / 2 - 32;
    return Container(
      color: Colors.white,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          // 总金额区块
          _buildTotalAmountCard(),
          SizedBox(width: 10),
          // 功能区块网格
          Expanded(
              child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              _buildFinanceItem(
                  "资金明细", 'assets/images/slices/组 7012@3x.png', width, 0.35),
              SizedBox(height: 10),
              Row(
                children: [
                  _buildFinanceItem("优惠卷", 'assets/images/slices/组 7014@3x.png',
                      width / 2 - 10, 0.75),
                  Expanded(child: SizedBox()),
                  _buildFinanceItem(
                      "我的积分",
                      'assets/images/slices/组 7013@3x.png',
                      width / 2 - 10,
                      0.75),
                ],
              )
            ],
          ))
        ],
      ),
    );
  }

  // 总金额卡片
  Widget _buildTotalAmountCard() {
    return Stack(
      children: [
        ImageLoader.asset(
            path: 'assets/images/slices/组 7015@3x.png',
            width: ScreenUtil.instance.designWidth / 2 - 16 * 2),
        Padding(
          padding: EdgeInsets.all(10),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Text(
                "总金额 (元)",
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 14,
                ),
              ),
              SizedBox(height: 10),
              Text(
                "1,6888.09",
                style: TextStyle(
                  fontSize: 18,
                  fontWeight: FontWeight.bold,
                  color: Colors.black,
                ),
              ),
            ],
          ),
        )
      ],
    );
  }

  // 功能项卡片
  Widget _buildFinanceItem(
      String title, String path, double width, double height) {
    return Stack(
      children: [
        ImageLoader.asset(path: path, width: width, height: width * height),
        Padding(
          padding: EdgeInsets.all(10),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Text(
                title,
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 14,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ],
          ),
        )
      ],
    );
  }
}
